//
//  TestMarqueeViewController.m
//  MKUITestApp
//
//  Created by 苏尚进 on 2025/9/24.
//  Copyright © 2025 moon. All rights reserved.
//

#import "TestMarqueeViewController.h"
#import "MKUIMarqueeView.h"
#import "TestElementHeaders.h"
@interface TestMarqueeViewCell : MKUIListPinHeadViewBase
@property(nonatomic,strong) MKUIMarqueeLabel *marqueeLabel;
@end
@implementation TestMarqueeViewCell
- (id)initWithFrame:(CGRect)frame{
    if(self=[super initWithFrame:frame]){
        self.backgroundColor = UIColor.whiteColor;
        self.marqueeLabel = [[MKUIMarqueeLabel alloc] init];
        self.marqueeLabel.contentInsets = MKUIEdgeInsetsMakeSameEdge(5);
        [self.marqueeLabel addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(_onDidTap:)]];
        [self.contentView addSubview:self.marqueeLabel];
    }
    return self;
}
- (void)_onDidTap:(id)sender{
    NSLog(@"didTap:%@",self.marqueeLabel.text);
}
- (void)layoutSubviews{
    [super layoutSubviews];
    CGRect bounds = self.contentView.bounds;
    self.marqueeLabel.frame = bounds;
}
- (CGSize)sizeThatFits:(CGSize)size{
    return [self.marqueeLabel sizeThatFits:size];
}
@end

@interface TestMarqueeViewController ()
@property(nonatomic,strong) TestMarqueeViewCell *marqueeCell;
@end

@implementation TestMarqueeViewController
+ (MKTFuncItem *)funcItem{
    return [MKTFuncItem funcWithName:@"测试跑马灯" viewControllerClass:self];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self reloadData];
}
- (void)reloadData{
    [self.listView deleteAllSections];
    @MK_WEAKIFY(self);
    
    //
    [self.listView addSection];
    self.marqueeCell = [[TestMarqueeViewCell alloc] init];
    MKUIMarqueeLabel *marqueeLabel = self.marqueeCell.marqueeLabel;
    marqueeLabel.text = @"这是一个跑马灯测试";
    [self.listView addItem:self.marqueeCell];
    //
    [self.listView addSection];
    [self.listView addItem:[MKUIElementListViewCellSelection testNSStringElementWithTitle:@"文本" selected:marqueeLabel.text whenDone:^(NSString * _Nonnull selectedValue) {
        @MK_NORMALIZEANDNOTNIL(self);
        marqueeLabel.text = selectedValue;
        [self.marqueeCell mk_reloadInListView];
    }]];
    //
    [self.listView addSection];
    //
    [self.listView addItem:[TestMKUIElementViewSlider testSliderElementWithTitle:@"speed" value:marqueeLabel.speed minimumValue:0.1 maximumValue:200 whenChange:^(TestMKUIElementViewSlider * _Nonnull el, CGFloat value) {
        @MK_NORMALIZEANDNOTNIL(self);
        marqueeLabel.speed = value;
    }]];
    [self.listView addItem:[MKUIElementListViewCellSwitch testSwitchElementWithTitle:@"enableAnimation" on:marqueeLabel.enableAnimation whenChange:^(BOOL on) {
        @MK_NORMALIZEANDNOTNIL(self);
        marqueeLabel.enableAnimation = on;
        [self.marqueeCell mk_reloadInListView];
    }]];
    [self.listView addItem:[MKUIElementListViewCellSwitch testSwitchElementWithTitle:@"animationBeginFromRightEdge" on:marqueeLabel.animationBeginFromRightEdge whenChange:^(BOOL on) {
        @MK_NORMALIZEANDNOTNIL(self);
        marqueeLabel.animationBeginFromRightEdge = on;
        [self.marqueeCell mk_reloadInListView];
    }]];
    
    [self.listView addItem:[MKUIElementListViewCellSwitch testSwitchElementWithTitle:@"不限行数" on:marqueeLabel.numberOfLines==0 whenChange:^(BOOL on) {
        @MK_NORMALIZEANDNOTNIL(self);
        marqueeLabel.numberOfLines = on?0:1;
        [self.marqueeCell mk_reloadInListView];
    }]];
    [self.listView addItem:[MKUIElementListViewCellSelection testUIColorElementWithTitle:@"textColor" selected:marqueeLabel.textColor whenDone:^(UIColor * _Nonnull selectedValue) {
        marqueeLabel.textColor = selectedValue;
    }]];
    [self.listView addItem:[MKUIElementListViewCellSelection testUIColorElementWithTitle:@"backgroundColor" selected:marqueeLabel.backgroundColor whenDone:^(UIColor * _Nonnull selectedValue) {
        marqueeLabel.backgroundColor = selectedValue;
    }]];
    
    [self.listView addItem:[TestMKUIElementViewSlider_UIEdgeInsets testSliderElementWithTitle:@"contentInsets" value:marqueeLabel.contentInsets minimumValue:UIEdgeInsetsZero maximumValue:MKUIEdgeInsetsMakeSameEdge(20) whenChange:^(TestMKUIElementViewSlider_UIEdgeInsets * _Nonnull el, UIEdgeInsets value) {
        @MK_NORMALIZEANDNOTNIL(self);
        marqueeLabel.contentInsets = value;
        [self.marqueeCell mk_reloadInListView];
    }]];
    [self.listView addItem:[TestMKUIElementViewSlider testSliderElementWithTitle:@"fontSize" value:marqueeLabel.font.pointSize minimumValue:10 maximumValue:20 whenChange:^(TestMKUIElementViewSlider * _Nonnull el, CGFloat value) {
        @MK_NORMALIZEANDNOTNIL(self);
        marqueeLabel.font = [UIFont systemFontOfSize:value];
        [self.marqueeCell mk_reloadInListView];
    }]];
    //
    [self.listView addSection];
    
    [self.listView reloadData];
}

@end
